package cn.mw.cmdb.trigger;

import cn.mw.components.mongodb.entity.GroupCalculateMethodEnum;
import lombok.Data;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

@Data
public class MwCmdbNotifyDropdown {
    private List<Map> ruleType;
    private List<Map> type;
    private List<Map> function;
    private List<Map> conditionOpsType;
    private List<Map> valueType;
    private List<Map> scopeType;
    private List<Map> exeType;

    public void init(MessageSource messageSource){
        ruleType = new ArrayList<>();
        for(MwNofityRuleType mwNofityRuleType:MwNofityRuleType.values()){
            Map map = new LinkedHashMap();
            map.put("code", mwNofityRuleType.name());
            String key = TriggerConstants.RuleTypePrefix + mwNofityRuleType.name();
            String name = messageSource.getMessage(key, null, LocaleContextHolder.getLocale());
            map.put("name", name);
            ruleType.add(map);
        }

        type = new ArrayList<>();
        for (MwNotifyRuleConditionType mwNotifyRuleConditionType : MwNotifyRuleConditionType.values()) {
            Map map = new LinkedHashMap();
            map.put("code", mwNotifyRuleConditionType.name());
            String key = TriggerConstants.RuleConditionTypePrefix + mwNotifyRuleConditionType.name();
            String name = messageSource.getMessage(key, null, LocaleContextHolder.getLocale());
            map.put("name", name);
            type.add(map);
        }

        function = new ArrayList<>();
        for (GroupCalculateMethodEnum calculateMethodEnum : GroupCalculateMethodEnum.values()) {
            Map map = new LinkedHashMap();
            map.put("code", calculateMethodEnum.name());
            String key = TriggerConstants.CalculateMethodPrefix + calculateMethodEnum.name();
            String name = messageSource.getMessage(key, null, LocaleContextHolder.getLocale());
            map.put("name", name);
            function.add(map);
        }

        conditionOpsType = new ArrayList<>();
        for (ConditionOpsType opsType : ConditionOpsType.values()) {
            Map map = new LinkedHashMap();
            map.put("code", opsType.name());
            String key = TriggerConstants.ConditionOpsPrefix + opsType.name();
            String name = messageSource.getMessage(key, null, LocaleContextHolder.getLocale());
            map.put("name", name);
            conditionOpsType.add(map);
        }

        valueType = new ArrayList<>();
        for (ValueTypeEnum valueTypeEnum : ValueTypeEnum.values()) {
            Map map = new LinkedHashMap();
            map.put("code", valueTypeEnum.name());
            String key = TriggerConstants.ValueTypePrefix + valueTypeEnum.name();
            String name = messageSource.getMessage(key, null, LocaleContextHolder.getLocale());
            map.put("name", name);
            valueType.add(map);
        }

        scopeType = new ArrayList<>();
        for(MwNotifyScopeType notifyScopeType: MwNotifyScopeType.values()){
            Map map = new LinkedHashMap();
            map.put("code" ,notifyScopeType.name());
            String key = TriggerConstants.ScopeTypePrefix + notifyScopeType.name();
            String name = messageSource.getMessage(key ,null , LocaleContextHolder.getLocale());
            map.put("name" ,name);
            scopeType.add(map);
        }

        exeType = new ArrayList<>();
        for(MwNotifyExeType mwNotifyExeType: MwNotifyExeType.values()){
            Map map = new LinkedHashMap();
            map.put("code" ,mwNotifyExeType.name());
            String key = TriggerConstants.ExeTypePrefix + mwNotifyExeType.name();
            String name = messageSource.getMessage(key ,null , LocaleContextHolder.getLocale());
            map.put("name" ,name);
            exeType.add(map);
        }
    }


}
